package cs.android.lang;

import static cs.java.lang.Lang.set;

import cs.android.http.HttpClientImpl;
import cs.android.rpc.ServerRequestBase;

public class GetRequest extends ServerRequestBase {

	private String content;
	private final HttpClientImpl http = new HttpClientImpl();

	public GetRequest(String serverUrl) {
		http.setUrl(serverUrl);
	}

	public void add(String key, String value) {
		http.add(key, value);
	}

	public String getResponse() {
		return content;
	}

	public void run() {
		try {
			http.executeGet();
			content = http.getResponseString();
			if (set(content)) onLoaded(true);
			else onLoaded(false);
		} catch (final Exception e) {
			onFailed(e);
		}
		onDone();
	}

}
